from django.middleware.common import MiddlewareMixin
from utils.config import Config

from utils.result import R
from utils.status_code import StatusCodeEnum

class LoginMiddleware(MiddlewareMixin):

    def process_request(self,request):

        url_method = "{}{}".format(request.path,request.method)
        if url_method not in Config.WHITE_URL_LIST:
            user_pk = request.session.get("user_pk",None)

            if not user_pk:
                return R.other_result(StatusCodeEnum.NO_LOGIN_ERR).to_json_response()
    